<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.pizzaonline.utils.*"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="org.jdom.*" %>
<jsp:include page="hautDePage.jsp" flush="true">
	<jsp:param name="title" value="Modification d'un menu" />
</jsp:include>

<div class="blocTexte">
<h3>Modification d'un menu</h3>
<a href="index.jsp" >Retour à l'accueil</a>
<br /> 

<%
	//Utils.printHeader(out, "Modification", "css/style.css",null);
	String nomMenu = request.getParameter("menu");
%>

<%
	out.println("<form action=\"ModificationMenu\" method=\"post\">");
	out.println("<table align=\"center\">");
	out.println("<tr><td><label>Nom : </label></td>");
	out.println("<td><input type=\"text\" size=\"20\" name= \"nom_menu\" value=\""+nomMenu+"\" readonly /></td></tr>");
	out.println("<tr><td><label>Pizza : </label></td>");
	
	//Récupération des pizzas du fichier XML
	try{
		XMLControler.readXMLFile("carte.xml");
		List pizzas = XMLControler.getPizzas();
		Iterator iter = pizzas.iterator();
		out.println("<td><select name=\"pizza\">");
		while(iter.hasNext()){
			Element pizza = (Element)iter.next();
			String nomPizza = pizza.getAttributeValue("nomPizza");
			if(XMLControler.isMenuContainsPizza(nomPizza,nomMenu)){
				out.println("<option value=\""+nomPizza+"\" selected>"+nomPizza+"</option>");
			}
			else{
				out.println("<option value=\""+nomPizza+"\">"+nomPizza+"</option>");
			}
		}
		out.println("</select></td>");
		
		// On teste si le menu contient une boisson
		Attribute boisson = XMLControler.getBoissonOfMenu(nomMenu);
		if(boisson != null){
			out.println("<tr><td><label>Boisson : </label></td>");
			out.println("<td><select name=\"boisson\">");
			String nom_boisson = boisson.getValue();
			List boissons = XMLControler.getBoissons();
			iter = boissons.iterator();
			while(iter.hasNext()){
				Element temp = (Element)iter.next();
				String strBoisson = temp.getAttributeValue("nomBoisson");
				if(strBoisson.equals(nom_boisson)){
					out.println("<option value=\""+strBoisson+"\" selected>"+strBoisson+"</option>");
				}
				else{
					out.println("<option value=\""+strBoisson+"\">"+strBoisson+"</option>");
				}
			}
			out.println("</select></td></tr>");
		}
		
		// On teste si le menu contient une salade
		Attribute salade = XMLControler.getSaladOfMenu(nomMenu);
		if(salade != null){
			out.println("<tr><td><label>Salade : </label></td>");
			out.println("<td><select name=\"salade\">");
			String nom_salade = salade.getValue();
			List salades = XMLControler.getSalades();
			iter = salades.iterator();
			while(iter.hasNext()){
				Element temp = (Element)iter.next();
				String strSalade = temp.getAttributeValue("nomSalade");
				if(strSalade.equals(nom_salade)){
					out.println("<option value=\""+strSalade+"\" selected>"+strSalade+"</option>");
				}
				else{
					out.println("<option value=\""+strSalade+"\">"+strSalade+"</option>");
				}
			}
			out.println("</select></td></tr>");
		}
		
		// On teste si le menu contient un dessert
		Attribute dessert = XMLControler.getDessertOfMenu(nomMenu);
		if(dessert != null){
			out.println("<tr><td><label>Dessert : </label></td>");
			out.println("<td><select name=\"dessert\">");
			String nom_dessert = dessert.getValue();
			List desserts = XMLControler.getDesserts();
			iter = desserts.iterator();
			while(iter.hasNext()){
				Element temp = (Element)iter.next();
				String strDessert = temp.getAttributeValue("nomDessert");
				if(strDessert.equals(nom_dessert)){
					out.println("<option value=\""+strDessert+"\" selected>"+strDessert+"</option>");
				}
				else{
					out.println("<option value=\""+strDessert+"\">"+strDessert+"</option>");
				}
			}
			out.println("</select></td></tr>");
		}
		
	}
	catch(Exception e){
		e.printStackTrace();
	}
	out.println("</tr>");
	out.println("<tr align=\"center\"><td colspan=\"2\">");
	out.println("<input type=\"submit\" value=\"Valider\" />");
	out.println("<input type=\"reset\" value=\"Réinitialiser\" /></td></tr>");
	out.println("</table></form>");
%>

<jsp:include page="basDePage.jsp" flush="true" />
<%
	//Utils.printFooter(out);
%>